/*
 * @Author: bor_fish 1219854025@qq.com
 * @Date: 2025-06-27 15:03:30
 * @LastEditors: bor_fish 1219854025@qq.com
 * @LastEditTime: 2025-06-29 00:55:52
 * @FilePath: /代码/LATENT_CONTROL_BOX_CAN.h
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#ifndef LATENT_CONTROL_BOX_CAN_H
#define LATENT_CONTROL_BOX_CAN_H

#include <cstdint>
#include <string>
#include <array>

class LATENT_CONTROL_BOX_CAN {
public:
// 阈值配置结构体
    struct TimingThresholds {
        int64_t output_no_response;    // 无输出阈值(微秒) - No response threshold (μs)
        int64_t output_too_fast;       // 输出过快阈值(微秒) - Output too fast threshold (μs)
        int64_t output_too_slow;       // 输出过慢阈值(微秒) - Output too slow threshold (μs)
        int64_t feedback_normal;       // 反馈正常阈值(微秒) - Normal feedback threshold (μs)
        int64_t feedback_slow;         // 反馈较慢阈值(微秒) - Slow feedback threshold (μs)
        int64_t feedback_no_response;  // 无反馈阈值(微秒) - No feedback threshold (μs)
    };
    struct TankLevelHeightThresholds {
        uint16_t max_tanklevelheight;   // 最大水舱液位高度 (100.00m) - Maximum tank level height (100.00m)
    };
    struct PressureGageThresholds {
        uint16_t max_pressuregage;      // 最大压力计压力 (60mpa) - Maximum pressure gage (60mpa)
    };

    // 阈值设置
    // 设置时序阈值 - Set timing thresholds
    static void setTimingThresholds(const TimingThresholds& thresholds);  
    // 设置当前水舱液位高度阈值 - Get tank level height thresholds
    static void setTankLevelHeightThresholds(const TankLevelHeightThresholds& thresholds); 
    // 设置当前压力计压力阈值 - Get pressure gage thresholds                        
    static void setPressureGageThresholds(const PressureGageThresholds& thresholds);                         


    // 阈值获取
    // 获取当前时序阈值 - Get current timing thresholds
    static TimingThresholds getCurrentThresholds();         
    // 获取当前水舱液位高度阈值 - Get tank level height thresholds
    static TankLevelHeightThresholds getTankLevelHeightThresholds(); 
    // 获取当前压力计压力阈值 - Get pressure gage thresholds   
    static PressureGageThresholds getPressureGageThresholds(); 

    // 状态检查
    static int checkOutputTiming(int64_t timeInterval);     // 检查输出时序 - Check output timing
    static int checkFeedbackTiming(int64_t timeBack);       // 检查反馈时序 - Check feedback timing

    // 数据解析
    static uint8_t parseWorkPattern(const uint8_t data[], size_t offset);   // 解析工作模式 - Parse work pattern
    static uint8_t parseSeaValve(const uint8_t data[], size_t offset);      // 解析通海阀 - Parse sea valve
    static uint8_t parseVentValveB(const uint8_t data[], size_t offset);    // 解析通气阀B - parse vent valve B
    static uint8_t parseWaterTankVentValveA1(const uint8_t data[], size_t offset);// 解析水舱通气阀A1 - Water tank ventilation valve A1
    static uint8_t parseWaterTankVentValveA2(const uint8_t data[], size_t offset);// 解析水舱通气阀A2 - Water tank ventilation valve A2
    static uint8_t parseWaterTankVentValveA3(const uint8_t data[], size_t offset);// 解析水舱通气阀A3 - Water tank ventilation valve A3
    static uint8_t parseWaterTankVentValveA4(const uint8_t data[], size_t offset);// 解析水舱通气阀A4 - Water tank ventilation valve A4
    static uint8_t parseAirSourceSelection(const uint8_t data[], size_t offset);// 解析气源选择 - Air source selection
    static uint8_t parseWaterTankBlow14(const uint8_t data[], size_t offset);// 解析水舱吹除14 - Water tank blow 14
    static uint8_t parseWaterTankBlow23(const uint8_t data[], size_t offset);// 解析水舱吹除23 - Water tank blow 23
    static uint8_t parseOperationModeStatus(const uint8_t data[], size_t offset);// 解析操作模式状态 - Operation mode status
    static uint8_t parseWorkingModeStatus(const uint8_t data[], size_t offset);// 解析工作模式状态 - Working mode status
    static uint16_t parsePort1TankLevel(const uint8_t data[], size_t offset);// 解析左舷1水舱液位 - Port 1 tank level
    static uint16_t parseStarboard1TankLevel(const uint8_t data[], size_t offset);// 解析右舷1水舱液位 - Starboard 1 tank level
    static uint16_t parsePort2TankLevel(const uint8_t data[], size_t offset);// 解析左舷2水舱液位 - Port 2 tank level
    static uint16_t parseStarboard2TankLevel(const uint8_t data[], size_t offset);// 解析右舷2水舱液位 - Starboard 2 tank level
    static uint16_t parsePort3TankLevel(const uint8_t data[], size_t offset);// 解析左舷3水舱液位 - Port 3 tank level
    static uint16_t parseStarboard3TankLevel(const uint8_t data[], size_t offset);// 解析右舷3水舱液位 - Starboard 3 tank level
    static uint16_t parsePort4TankLevel(const uint8_t data[], size_t offset);// 解析左舷4水舱液位 - Port 4 tank level
    static uint16_t parseStarboard4TankLevel(const uint8_t data[], size_t offset);// 解析右舷4水舱液位 - Starboard 4 tank level
    static uint16_t parseVentvalveAStatus(const uint8_t data[], size_t offset);// 解析通气阀A - Ventilation valve A
    static uint16_t parseVentvalveBStatus(const uint8_t data[], size_t offset);// 解析通气阀B - Ventilation valve B
    static uint16_t parseSeaValveStatus(const uint8_t data[], size_t offset);// 解析通海阀 - Sea valve
    static uint8_t parseHighPressureBlowoutValveStatus(const uint8_t data[], size_t offset);// 解析高压吹除阀 - High pressure blowout valve
    static uint16_t parsePressureGage1(const uint8_t data[], size_t offset);// 解析压力计1 - pressure gage 1
    static uint16_t parsePressureGage2(const uint8_t data[], size_t offset);// 解析压力计2 - pressure gage 2
    static uint16_t parsePressureGage3(const uint8_t data[], size_t offset);// 解析压力计3 - pressure gage 3
    static uint16_t parsePressureGage4(const uint8_t data[], size_t offset);// 解析压力计4 - pressure gage 4
    static uint16_t parsePressureGage5(const uint8_t data[], size_t offset);// 解析压力计5 - pressure gage 5
    static uint16_t parsePressureGage6(const uint8_t data[], size_t offset);// 解析压力计6 - pressure gage 6
    static uint16_t parsePressureGage7(const uint8_t data[], size_t offset);// 解析压力计7 - pressure gage 7
    static uint16_t parsePressureGage8(const uint8_t data[], size_t offset);// 解析压力计8 - pressure gage 8
    static uint16_t parsePressureGage9(const uint8_t data[], size_t offset);// 解析压力计9 - pressure gage 9
    static uint16_t parsePressureGage10(const uint8_t data[], size_t offset);// 解析压力计10 - pressure gage 10
    static uint16_t parsePressureGage11(const uint8_t data[], size_t offset);// 解析压力计11 - pressure gage 11
    static uint8_t parseFaultBits1(const uint8_t* data, size_t offset);     // 解析故障位1 - Parse fault bits 1
    static uint8_t parseFaultBits2(const uint8_t* data, size_t offset);     // 解析故障位2 - Parse fault bits 2

    
    // 状态检查
    static int checkWorkPattern(const uint8_t data[], size_t offset);       // 检查工作模式 - Check work pattern
    static int checkSeaValve(const uint8_t data[], size_t offset);          // 检查通海阀 - Check sea valve
    static int checkVentValveB(const uint8_t data[], size_t offset);        // 检查通气阀B - Check vent valve B
    static int checkWaterTankVentValveA1(const uint8_t data[], size_t offset);// 检查水舱通气阀A1 - Water tank ventilation valve A1
    static int checkWaterTankVentValveA2(const uint8_t data[], size_t offset);// 检查水舱通气阀A2 - Water tank ventilation valve A2
    static int checkWaterTankVentValveA3(const uint8_t data[], size_t offset);// 检查水舱通气阀A3 - Water tank ventilation valve A3
    static int checkWaterTankVentValveA4(const uint8_t data[], size_t offset);// 检查水舱通气阀A4 - Water tank ventilation valve A4
    static int checkAirSourceSelection(const uint8_t data[], size_t offset);// 检查气源选择 - Air source selection
    static int checkWaterTankBlow14(const uint8_t data[], size_t offset);// 检查水舱吹除14 - Water tank blow 14
    static int checkWaterTankBlow23(const uint8_t data[], size_t offset);// 检查水舱吹除23 - Water tank blow 23
    static int checkOperationModeStatus(const uint8_t data[], size_t offset);// 检查操作模式状态 - Operation mode status
    static int checkWorkingModeStatus(const uint8_t data[], size_t offset);// 检查工作模式状态 - Working mode status
    static uint16_t checkPort1TankLevel(const uint8_t data[], size_t offset);// 检查左舷1水舱液位 - Port 1 tank level
    static uint16_t checkStarboard1TankLevel(const uint8_t data[], size_t offset);// 检查右舷1水舱液位 - Starboard 1 tank level
    static uint16_t checkPort2TankLevel(const uint8_t data[], size_t offset);// 检查左舷2水舱液位 - Port 2 tank level
    static uint16_t checkStarboard2TankLevel(const uint8_t data[], size_t offset);// 检查右舷2水舱液位 - Starboard 2 tank level
    static uint16_t checkPort3TankLevel(const uint8_t data[], size_t offset);// 检查左舷3水舱液位 - Port 3 tank level
    static uint16_t checkStarboard3TankLevel(const uint8_t data[], size_t offset);// 检查右舷3水舱液位 - Starboard 3 tank level
    static uint16_t checkPort4TankLevel(const uint8_t data[], size_t offset);// 检查左舷4水舱液位 - Port 4 tank level
    static uint16_t checkStarboard4TankLevel(const uint8_t data[], size_t offset);// 检查右舷4水舱液位 - Starboard 4 tank level
    static uint16_t checkVentvalveAStatus(const uint8_t data[], size_t offset);// 检查通气阀A - Ventilation valve A
    static uint16_t checkVentvalveBStatus(const uint8_t data[], size_t offset);// 检查通气阀B - Ventilation valve B
    static uint16_t checkSeaValveStatus(const uint8_t data[], size_t offset);// 检查通海阀 - Sea valve
    static uint8_t checkHighPressureBlowoutValveStatus(const uint8_t data[], size_t offset);// 检查高压吹除阀 - High pressure blowout valve
    static uint16_t checkPressureGage1(const uint8_t data[], size_t offset);// 检查压力计1 - pressure gage 1
    static uint16_t checkPressureGage2(const uint8_t data[], size_t offset);// 检查压力计2 - pressure gage 2
    static uint16_t checkPressureGage3(const uint8_t data[], size_t offset);// 检查压力计3 - pressure gage 3
    static uint16_t checkPressureGage4(const uint8_t data[], size_t offset);// 检查压力计4 - pressure gage 4
    static uint16_t checkPressureGage5(const uint8_t data[], size_t offset);// 检查压力计5 - pressure gage 5
    static uint16_t checkPressureGage6(const uint8_t data[], size_t offset);// 检查压力计6 - pressure gage 6
    static uint16_t checkPressureGage7(const uint8_t data[], size_t offset);// 检查压力计7 - pressure gage 7
    static uint16_t checkPressureGage8(const uint8_t data[], size_t offset);// 检查压力计8 - pressure gage 8
    static uint16_t checkPressureGage9(const uint8_t data[], size_t offset);// 检查压力计9 - pressure gage 9
    static uint16_t checkPressureGage10(const uint8_t data[], size_t offset);// 检查压力计10 - pressure gage 10
    static uint16_t checkPressureGage11(const uint8_t data[], size_t offset);// 检查压力计11 - pressure gage 11
    static int checkFaultBits1Status(const uint8_t* data, size_t offset);       // 检查故障位1状态 - Check fault bits 1
    static int checkFaultBits2Status(const uint8_t* data, size_t offset);       // 检查故障位2状态 - Check fault bits 2

private:
    static TimingThresholds currentTimingThresholds;            // 当前时序阈值 - Current timing thresholds
    static TankLevelHeightThresholds tanklevelHeightThresholds; // 当前水舱液位高度阈值 - Tank level height thresholds
    static PressureGageThresholds pressuregageThresholds;       // 当前压力计压力阈值 - pressure gage thresholds
};

#endif
